package com.hdl.mapper;

import com.hdl.pojo.Order;
import com.hdl.pojo.User;
import com.sun.org.apache.xpath.internal.operations.Or;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 接口名 IOrderMapper
 * 描述 订单持久层接口
 *
 * @author hedonglin
 * @version 1.0
 * @date 2020/4/22 19:51
 */
public interface IOrderMapper {

    /**
     * 查询订单的同时还查询该订单所属用户
     */
    @Results({
        @Result(property = "id", column = "id"),
        @Result(property = "orderTime", column = "orderTime"),
        @Result(property = "total", column = "total"),
        @Result(property = "user", column = "uid", javaType = User.class,
                one = @One(select = "com.hdl.mapper.IUserMapper.findUserById"))
     })
    @Select("select * from  orders")
    List<Order> findOrderAndUser();


    @Select("select * from orders where uid = #{userId}")
    List<Order> findOrderByUserId(Integer userId);

}
